<?php
class TdMenu extends TdComponent {
	
	public $items;
	public $separator;
	public $pre;
	public $post;
  public $preitem;
  public $postitem;
	
	function __construct($id, $template="") {
		parent::__construct($id, $template);
	}
	
	function addItem($label, $link) {
		$this->items[$link] = $label;
	}
	function setItems($items) {
		$this->items = $items;
	}
  function getItems() {
  	return $this->items;
  }
  
  function setSeparator($value) {
  	$this->separator = $value;
  }
  function getSeparator() {
  	return $this->separator;
  }
  
  function setPre($value) {
  	$this->pre = $value;
  }
  function getPre() {
  	return $this->pre;
  }
  
  function setPost($value) {
  	$this->post = $value;
  }
  function getPost() {
  	return $this->post;
  }
  
  function setPreItem($value) {
  	$this->preitem = $value;
  }
  function getPreItem() {
  	return $this->preitem;
  }
  
  function setPostItem($value) {
  	$this->postitem = $value;
  }
  function getPostItem() {
  	return $this->postitem;
  }
  
  function __toString() {
  	$pout = parent::__toString();
  	if ($pout != "") {
  		return $pout;
  	}
  	 
  	ob_start();
  	
  	if (isset($this->pre)) print($this->pre);
  	$total_items = count($this->items);
  	$count_items = 1;
    foreach ($this->items as $link => $label) {
    	if (isset($this->preitem)) print($this->preitem);
    	print("<a href=\"".$link."\">".$label."</a>");
    	if (isset($this->postitem)) print($this->postitem);
    	if (isset($this->separator) && $count_items < $total_items) {
    		print($this->separator);
    	}
    	$count_items++;
    }
  	if (isset($this->post)) print($this->post);
  	return ob_get_clean();
  }
}